package com.mf.controller;

import com.mf.entity.Msg;
import com.mf.entity.Music;
import com.mf.entity.Picture;
import com.mf.service.MusicService;
import com.mf.service.PictureService;
import com.mf.util.DeleteFileUtil;

public class MusicController {
	
	MusicService musicService=new MusicService();
	PictureService pictureService =new PictureService();
	Music music =new Music();
	Picture picture=new Picture();
	
	public Msg getAllMusic(){
		return Msg.success().add("musiclist", musicService.getAllMusic());
	}
	
	public Msg delMusic(String id,String picrealname,String musicrealname){
		
		int intId=Integer.parseInt(id);
		musicService.delMusic(intId);
		Picture picture=pictureService.findPictureByRealname(picrealname);
		pictureService.delete(picture);
		DeleteFileUtil.deleteFile("/home/upload/imgs/"+picrealname);
		DeleteFileUtil.deleteFile("/home/upload/imgs/"+musicrealname);
		return Msg.success();
	}
	
	public Msg getMusic(String id){
		
		music=musicService.getMusic(id);
		picture=pictureService.findPictureByRealname(music.getPictitle());
		return Msg.success().add("music", music).add("picture", picture);
	}
	
	public Msg musicUpate(Music music,Picture picture){
		
		musicService.updateMusic(music);
		pictureService.update(picture);
		return Msg.success();
	}
	
}
